<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>叩丁狼权限管理系统</title>
    <#include "../common/header.ftl" >
    <script type="text/javascript" src="/jquery/plugins/jquery.form.js" ></script>
    <script type="text/javascript" src="/jquery/plugins/jquery.bootstrap.min.js"></script>
    <!--导入日期插件-->
    <script type="text/javascript" src="/jquery/My97DatePicker/WdatePicker.js"></script>
    <style>
        .modal-body img{
            width: 100%;
        }
    </style>
    <script>
        $(function () {
            // 查看文章按钮
            $(".look_Btn").click(function () {
                var id = $(this).data("id");
                //发送ajax请求,查询对应id的游记内容
                $.get("/travels/getById.do",{"id":id},function (data) {
                    $(".modal-body travelModal").html(" 他,神马都没有留下......");
                    $(".modal-body travelModal").html(data.content); // 回显游记的具体内容
                })
                $("#travelModal").modal("show");
            })

            // 取消发布按钮 / 取消发布后的状态更改为  --> 拒绝
            $(".changeStateBtn").click(function () {
                var travelId = $(this).data("id");
                // 游记的状态
                var state = $(this).data("state");
                $.get("/travels/changeState.do",{"id":travelId,"state":state},function (data) {
                    if(data.success){
                        $.messager.alert("温馨提示","操作成功!");
                        setTimeout(function () {
                            window.location.reload();
                        },500);
                    }
                })
            });

            // 推荐游记按钮
            $(".commendBtn").click(function () {
                // 获取绑定数据
                var json = $(this).data("json");
                // 回显数据
                if (json) {  // 编辑按钮
                    //回显数据
                    $("input[name='travel.id']").val(json.id);
                    $("input[name=title]").val(json.title);
                    // 将封面回显给用户看
                    $(".coverUrl").attr("src",json.coverUrl);
                    // 将图片回显在input标签
                     $("input[name=coverUrl]").val(json.coverUrl);
                    $("#commendModal").modal("show");
                }
            })
            // 保存模态框里的数据
            $(".btn-submit").click(function (data) {
                //将表单的提交方式修改为ajax异步提交
                $("#editForm").ajaxSubmit(function (data) {
                    if(data.success){
                        $.messager.alert("温馨提示","操作成功!");
                        setTimeout(function () {
                            window.location.reload();
                        },500);
                    }
                })
            })

        })
    </script>
</head>
<body>

<div class="container " style="margin-top: 20px">
    <#include "../common/top.ftl">
    <div class="row">
        <div class="col-sm-3">
            <#assign currentMenu="releaseList"/>
            <#include "../common/menu.ftl">
        </div>
        <div class="col-sm-9">
            <div class="row">
                <div class="col-sm-12">
                    <h1 class="page-head-line">已发布游记管理</h1>
                </div>

                <!--高级查询--->
                <form class="form-inline" id="searchForm" action="/travels/releaseList.do" method="post">
                    <input type="hidden" name="currentPage" id="currentPage" value="1">
                    <div class="form-group">
                        <label for="keyword">关键字:</label>
                        <input type="text" class="form-control" id="keyword" name="keyword" value="${(qo.keyword)!}" placeholder="请输入游记标题">
                    </div>
                    <input type="submit" id="btn_query" class="btn btn-default btn-success" value="查询">
                </form>
            </div>

            <table class="table table-striped table-hover">
                <thead>
                <tr>
                    <th>编号</th>
                    <th>标题</th>
                    <th>封面</th>
                    <th>地点</th>
                    <th>作者</th>
                    <th>状态</th>
                </tr>
                </thead>
                <#list pageInfo.list as entity>
                    <tr>
                        <td>${entity_index+1}</td>
                        <td>${entity.title}</td>
                        <td>
                            <img width="40px" height="40px" src="${(entity.headImgUrl)!}">
                        </td>
                        <td>${entity.place.name}</td>
                        <td>${(entity.author.nickName)!}</td>
                        <td>${(entity.stateName)!}</td>
                        <td>
                            <a href="javascript:void(0);" class="changeStateBtn" data-state="-1" data-id="${entity.id}">取消发布</a>
                        </td>
                        <td>
                            <a href="javascript:void(0);" class="look_Btn" data-id="${entity.id}">看文章</a>
                        </td>
                        <td>
                            <a href="javascript:void(0);" class="commendBtn" data-json='${(entity.json)!}'>推荐</a>
                        </td>
                    </tr>
                </#list>
            </table>
            <#include "../common/page.ftl" />
        </div>
    </div>
</div>
<#--查看内容模态框-->
<div class="modal fade" id="travelModal" tabindex="-1" role="dialog">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span>
                </button>
                <h4 class="modal-title">查看内容</h4>
            </div>
            <div class="modal-body content">

            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                <button type="button" class="btn btn-primary btn-submit">保存</button>
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal-dialog -->
</div><!-- /.modal -->

<#--设置推荐模态框-->
<div class="modal fade" id="commendModal" tabindex="-1" role="dialog">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span>
                </button>
                <h4 class="modal-title">新增游记推荐</h4>
            </div>
            <div class="modal-body">
                <form class="form-horizontal" action="/travelcommends/saveOrUpdate.do" method="post" id="editForm" enctype="multipart/form-data">
                    <input type="hidden" name="travel.id"><#--记录游记的id-->
                    <div class="form-group">
                        <label for="name" class="col-sm-2 control-label">标题：</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" id="title" name="title"
                                   placeholder="请输入游记标题">
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="name" class="col-sm-2 control-label">副标题：</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" id="subTitle" name="subTitle"
                                   placeholder="请输入游记副标题">
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="name" class="col-sm-2 control-label">封面：</label>
                        <div class="col-sm-6">
                            <img width="100%" class="coverUrl"/>
                                <input type="hidden" class="form-control" id="coverUrl" name="coverUrl">
                            <input type="file" id="fileInput" class="form-control" name="file"/>
                            <script>
                                    $("#fileInput").click(function () {
                                        console.log($(this).val());
                                        if ($(this).val()) {
                                            $.get("/images",function (data) {
                                                console.log(data);
                                                if (data.status == 1) { // data.status 等于1 -> 上传成功
                                                    // 回显图片
                                                    $(".coverUrl").attr("src", data.url);
                                                    $("#editForm input[name=coverUrl").val(data.url);
                                                }
                                            })
                                        }
                                    })

                            </script>

                        </div>
                    </div>


                    <div class="form-group">
                        <label for="name" class="col-sm-2 control-label">推荐时间：</label>
                        <div class="col-sm-6">
                            <#-- onclick="WdatePicker() 这样设置的作用: 点击这个input输入框的时候弹出时间插件 -->
                            <input type="text" class="form-control" id="schedule" name="schedule"
                                   placeholder="请输选择推荐时间" onclick="WdatePicker();">
                        </div>
                    </div>


                    <div class="form-group">
                        <label for="sn" class="col-sm-2 control-label">推荐类型：</label>
                        <div class="col-sm-6">
                            <select class="form-control" autocomplete="off" name="type">
                                <option value="1">每周推荐</option>
                                <option value="2">每月推荐</option>
                                <option value="3">攻略推荐</option>
                            </select>
                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                <button type="button" class="btn btn-primary btn-submit">保存</button>
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal-dialog -->
</div><!-- /.modal -->

</body>
</html>